package com.qdlc.p2p.biz.processor.task.pay;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.processor.event.BorrowRepayValueEvent;
import com.qdlc.p2p.biz.processor.task.AbstractTaskProcessor;
import com.qdlc.p2p.biz.service.CollectPayService;
import com.qdlc.p2p.common.core.queue.TaskProcessorException;
import com.qdlc.p2p.common.core.queue.ValueEvent;
import com.qdlc.p2p.dal.dto.TppTradeLog;

/**
 * PS 还款代付
 *
 * @author wuaj
 */
@Service
public class BorrowRepayPayTaskProcessor extends AbstractTaskProcessor {

    @Resource
    @Qualifier("borrowRepayPayService")
    private CollectPayService borrowRepayPayService;

    @Override
    public boolean supports(ValueEvent event) {
        return event instanceof BorrowRepayValueEvent;
    }

    @Override
    public void process0(ValueEvent e) throws TaskProcessorException {
        BorrowRepayValueEvent borrowRepayValueEvent = (BorrowRepayValueEvent)e;
        List<TppTradeLog> tppTradeLogs = borrowRepayValueEvent.getTppTradeLogs();
        for(TppTradeLog tppTradeLog : tppTradeLogs) {
            // 代付请求
            borrowRepayPayService.requestOrder(tppTradeLog);
        }
    }
}